<template>
  <div>
    <VRow class="lf-config-row">
      <VCol cols="12">
        <VTextField
          v-model="taskId"
          class="lf-config-item"
          counter
          maxlength="50"
          color="success"
          hint="任务ID"
          label="任务ID"
        />
      </VCol>
      <VCol cols="12">
        <VTextField
          v-model="taskName"
          class="lf-config-item"
          counter
          maxlength="50"
          color="success"
          hint="任务名称"
          label="任务名称"
        />
      </VCol>
    </VRow>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({		
  currRow: Object,
  addUrl: String,
  updateUrl: String,
})

const emits = defineEmits(['refreshPage'])

const addUrl = ref(props.addUrl)
const updateUrl = ref(props.updateUrl)

const currRow = ref(props.currRow)
const row = currRow.value

const isEdit = ref(!!row.id)

const id = ref(row.id || '')
const taskId = ref(row.taskId || '')
const taskName = ref(row.taskName || '')

const getUrl = () => {
  if(isEdit.value){
    return updateUrl.value
  }
  
  return addUrl.value
}

const saveItem = async () => {
  const res = await $ivyApi.post(getUrl(),{
    id: id.value,
    taskId: taskId.value,
    taskName: taskName.value,
  })
  emits('refreshPage', res)
}



defineExpose({
  saveItem,
})

onMounted(() => {

})
</script>

<style scoped>
.lf-config-row .v-col {
  padding-block-end: 3px;
}

.lf-config-item {
  padding-block-start: 8px;
}
</style>
